<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Parser Basics</title>
<link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../../index.html" title="Spirit 2.59">
<link rel="up" href="../reference.html" title="Reference">
<link rel="prev" href="parser_concepts/nonterminal.html" title="Nonterminal">
<link rel="next" href="parse_api.html" title="Parser API">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="parser_concepts/nonterminal.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../reference.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="parse_api.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="spirit.qi.reference.basics"></a><a class="link" href="basics.html" title="Parser Basics">Parser Basics</a>
</h4></div></div></div>
<h6>
<a name="spirit.qi.reference.basics.h0"></a>
          <span class="phrase"><a name="spirit.qi.reference.basics.lazy_argument"></a></span><a class="link" href="basics.html#spirit.qi.reference.basics.lazy_argument">Lazy
          Argument</a>
        </h6>
<p>
          Some parsers (e.g. primitives and non-terminals) may take in additional
          attributes. Such parsers take the form:
        </p>
<pre class="programlisting"><span class="identifier">p</span><span class="special">(</span><span class="identifier">a1</span><span class="special">,</span> <span class="identifier">a2</span><span class="special">,...,</span> <span class="identifier">aN</span><span class="special">)</span>
</pre>
<p>
          where <code class="computeroutput"><span class="identifier">p</span></code> is a parser. Each
          of the arguments (a1 ... aN) can either be an immediate value, or a function,
          <code class="computeroutput"><span class="identifier">f</span></code>, with signature:
        </p>
<pre class="programlisting"><span class="identifier">T</span> <span class="identifier">f</span><span class="special">(</span><span class="identifier">Unused</span><span class="special">,</span> <span class="identifier">Context</span><span class="special">)</span>
</pre>
<p>
          where <code class="computeroutput"><span class="identifier">T</span></code>, the function's
          return value, is compatible with the argument type expected and <code class="computeroutput"><span class="identifier">Context</span></code> is the parser's Context type
          (The first argument is <code class="computeroutput"><span class="identifier">unused</span></code>
          to make the <code class="computeroutput"><span class="identifier">Context</span></code> the
          second argument. This is done for uniformity with Semantic Actions).
        </p>
<h6>
<a name="spirit.qi.reference.basics.h1"></a>
          <span class="phrase"><a name="spirit.qi.reference.basics.character_encoding_namespace"></a></span><a class="link" href="basics.html#spirit.qi.reference.basics.character_encoding_namespace">Character
          Encoding Namespace</a>
        </h6>
<p>
          Some parsers need to know which character set a <code class="computeroutput"><span class="keyword">char</span></code>
          or <code class="computeroutput"><span class="keyword">wchar_t</span></code> is operating on.
          For example, the <code class="computeroutput"><span class="identifier">alnum</span></code>
          parser works differently with ISO8859.1 and ASCII encodings. Where necessary,
          Spirit encodes (tags) the parser with the character set.
        </p>
<p>
          We have a namespace for each character set Spirit will be supporting. That
          includes <code class="computeroutput"><span class="identifier">ascii</span></code>, <code class="computeroutput"><span class="identifier">iso8859_1</span></code>, <code class="computeroutput"><span class="identifier">standard</span></code>
          and <code class="computeroutput"><span class="identifier">standard_wide</span></code> (and
          in the future, <code class="computeroutput"><span class="identifier">unicode</span></code>).
          In each of the character encoding namespaces, we place tagged versions
          of parsers such as <code class="computeroutput"><span class="identifier">alnum</span></code>,
          <code class="computeroutput"><span class="identifier">space</span></code> etc.
        </p>
<p>
          Example:
        </p>
<pre class="programlisting"><span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">ascii</span><span class="special">::</span><span class="identifier">space</span><span class="special">;</span> <span class="comment">// use the ASCII space parser</span>
</pre>
<p>
          Namespaces:
        </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
              boost::spirit::ascii
            </li>
<li class="listitem">
              boost::spirit::iso8859_1
            </li>
<li class="listitem">
              boost::spirit::standard
            </li>
<li class="listitem">
              boost::spirit::standard_wide
            </li>
</ul></div>
<p>
          For ease of use, the components in this namespaces are also brought into
          the qi sub-namespaces with the same names:
        </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
              boost::spirit::qi::ascii
            </li>
<li class="listitem">
              boost::spirit::qi::iso8859_1
            </li>
<li class="listitem">
              boost::spirit::qi::standard
            </li>
<li class="listitem">
              boost::spirit::qi::standard_wide
            </li>
</ul></div>
<h6>
<a name="spirit.qi.reference.basics.h2"></a>
          <span class="phrase"><a name="spirit.qi.reference.basics.examples"></a></span><a class="link" href="basics.html#spirit.qi.reference.basics.examples">Examples</a>
        </h6>
<p>
          All sections in the reference present some real world examples. The examples
          use a common test harness to keep the example code as minimal and direct
          to the point as possible. The test harness is presented below.
        </p>
<p>
          Some includes:
        </p>
<p>
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">spirit</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">support_utree</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">spirit</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">qi</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">phoenix</span><span class="special">/</span><span class="identifier">core</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">phoenix</span><span class="special">/</span><span class="keyword">operator</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">fusion</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">adapt_struct</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">assert</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">predef</span><span class="special">/</span><span class="identifier">other</span><span class="special">/</span><span class="identifier">endian</span><span class="special">.</span><span class="identifier">h</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">proto</span><span class="special">/</span><span class="identifier">deep_copy</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iostream</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">string</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">cstdlib</span><span class="special">&gt;</span>
</pre>
<p>
        </p>
<p>
          Our test functions:
        </p>
<p>
          These functions test the parsers without attributes.
        </p>
<p>
</p>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">P</span><span class="special">&gt;</span>
<span class="keyword">void</span> <span class="identifier">test_parser</span><span class="special">(</span>
    <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">input</span><span class="special">,</span> <span class="identifier">P</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">p</span><span class="special">,</span> <span class="keyword">bool</span> <span class="identifier">full_match</span> <span class="special">=</span> <span class="keyword">true</span><span class="special">)</span>
<span class="special">{</span>
    <span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">qi</span><span class="special">::</span><span class="identifier">parse</span><span class="special">;</span>

    <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">f</span><span class="special">(</span><span class="identifier">input</span><span class="special">);</span>
    <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">l</span><span class="special">(</span><span class="identifier">f</span> <span class="special">+</span> <span class="identifier">strlen</span><span class="special">(</span><span class="identifier">f</span><span class="special">));</span>
    <span class="keyword">if</span> <span class="special">(</span><span class="identifier">parse</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">l</span><span class="special">,</span> <span class="identifier">p</span><span class="special">)</span> <span class="special">&amp;&amp;</span> <span class="special">(!</span><span class="identifier">full_match</span> <span class="special">||</span> <span class="special">(</span><span class="identifier">f</span> <span class="special">==</span> <span class="identifier">l</span><span class="special">)))</span>
        <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"ok"</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
    <span class="keyword">else</span>
        <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"fail"</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
<span class="special">}</span>

<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">P</span><span class="special">&gt;</span>
<span class="keyword">void</span> <span class="identifier">test_phrase_parser</span><span class="special">(</span>
    <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">input</span><span class="special">,</span> <span class="identifier">P</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">p</span><span class="special">,</span> <span class="keyword">bool</span> <span class="identifier">full_match</span> <span class="special">=</span> <span class="keyword">true</span><span class="special">)</span>
<span class="special">{</span>
    <span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">qi</span><span class="special">::</span><span class="identifier">phrase_parse</span><span class="special">;</span>
    <span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">qi</span><span class="special">::</span><span class="identifier">ascii</span><span class="special">::</span><span class="identifier">space</span><span class="special">;</span>

    <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">f</span><span class="special">(</span><span class="identifier">input</span><span class="special">);</span>
    <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">l</span><span class="special">(</span><span class="identifier">f</span> <span class="special">+</span> <span class="identifier">strlen</span><span class="special">(</span><span class="identifier">f</span><span class="special">));</span>
    <span class="keyword">if</span> <span class="special">(</span><span class="identifier">phrase_parse</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">l</span><span class="special">,</span> <span class="identifier">p</span><span class="special">,</span> <span class="identifier">space</span><span class="special">)</span> <span class="special">&amp;&amp;</span> <span class="special">(!</span><span class="identifier">full_match</span> <span class="special">||</span> <span class="special">(</span><span class="identifier">f</span> <span class="special">==</span> <span class="identifier">l</span><span class="special">)))</span>
        <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"ok"</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
    <span class="keyword">else</span>
        <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"fail"</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
<span class="special">}</span>
</pre>
<p>
        </p>
<p>
          These functions test the parsers with user supplied attributes.
        </p>
<p>
</p>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">P</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">void</span> <span class="identifier">test_parser_attr</span><span class="special">(</span>
    <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">input</span><span class="special">,</span> <span class="identifier">P</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">p</span><span class="special">,</span> <span class="identifier">T</span><span class="special">&amp;</span> <span class="identifier">attr</span><span class="special">,</span> <span class="keyword">bool</span> <span class="identifier">full_match</span> <span class="special">=</span> <span class="keyword">true</span><span class="special">)</span>
<span class="special">{</span>
    <span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">qi</span><span class="special">::</span><span class="identifier">parse</span><span class="special">;</span>

    <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">f</span><span class="special">(</span><span class="identifier">input</span><span class="special">);</span>
    <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">l</span><span class="special">(</span><span class="identifier">f</span> <span class="special">+</span> <span class="identifier">strlen</span><span class="special">(</span><span class="identifier">f</span><span class="special">));</span>
    <span class="keyword">if</span> <span class="special">(</span><span class="identifier">parse</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">l</span><span class="special">,</span> <span class="identifier">p</span><span class="special">,</span> <span class="identifier">attr</span><span class="special">)</span> <span class="special">&amp;&amp;</span> <span class="special">(!</span><span class="identifier">full_match</span> <span class="special">||</span> <span class="special">(</span><span class="identifier">f</span> <span class="special">==</span> <span class="identifier">l</span><span class="special">)))</span>
        <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"ok"</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
    <span class="keyword">else</span>
        <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"fail"</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
<span class="special">}</span>

<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">P</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">void</span> <span class="identifier">test_phrase_parser_attr</span><span class="special">(</span>
    <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">input</span><span class="special">,</span> <span class="identifier">P</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">p</span><span class="special">,</span> <span class="identifier">T</span><span class="special">&amp;</span> <span class="identifier">attr</span><span class="special">,</span> <span class="keyword">bool</span> <span class="identifier">full_match</span> <span class="special">=</span> <span class="keyword">true</span><span class="special">)</span>
<span class="special">{</span>
    <span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">qi</span><span class="special">::</span><span class="identifier">phrase_parse</span><span class="special">;</span>
    <span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">qi</span><span class="special">::</span><span class="identifier">ascii</span><span class="special">::</span><span class="identifier">space</span><span class="special">;</span>

    <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">f</span><span class="special">(</span><span class="identifier">input</span><span class="special">);</span>
    <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">l</span><span class="special">(</span><span class="identifier">f</span> <span class="special">+</span> <span class="identifier">strlen</span><span class="special">(</span><span class="identifier">f</span><span class="special">));</span>
    <span class="keyword">if</span> <span class="special">(</span><span class="identifier">phrase_parse</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">l</span><span class="special">,</span> <span class="identifier">p</span><span class="special">,</span> <span class="identifier">space</span><span class="special">,</span> <span class="identifier">attr</span><span class="special">)</span> <span class="special">&amp;&amp;</span> <span class="special">(!</span><span class="identifier">full_match</span> <span class="special">||</span> <span class="special">(</span><span class="identifier">f</span> <span class="special">==</span> <span class="identifier">l</span><span class="special">)))</span>
        <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"ok"</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
    <span class="keyword">else</span>
        <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"fail"</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
<span class="special">}</span>
</pre>
<p>
        </p>
<p>
          The <code class="computeroutput"><span class="identifier">print_info</span></code> utility
          function prints information contained in the <code class="computeroutput"><span class="identifier">info</span></code>
          class.
        </p>
<p>
</p>
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">printer</span>
<span class="special">{</span>
    <span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">utf8_string</span> <span class="identifier">string</span><span class="special">;</span>

    <span class="keyword">void</span> <span class="identifier">element</span><span class="special">(</span><span class="identifier">string</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">tag</span><span class="special">,</span> <span class="identifier">string</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">value</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">depth</span><span class="special">)</span> <span class="keyword">const</span>
    <span class="special">{</span>
        <span class="keyword">for</span> <span class="special">(</span><span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">i</span> <span class="special">&lt;</span> <span class="special">(</span><span class="identifier">depth</span><span class="special">*</span><span class="number">4</span><span class="special">);</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span> <span class="comment">// indent to depth</span>
            <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="char">' '</span><span class="special">;</span>

        <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"tag: "</span> <span class="special">&lt;&lt;</span> <span class="identifier">tag</span><span class="special">;</span>
        <span class="keyword">if</span> <span class="special">(</span><span class="identifier">value</span> <span class="special">!=</span> <span class="string">""</span><span class="special">)</span>
            <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">", value: "</span> <span class="special">&lt;&lt;</span> <span class="identifier">value</span><span class="special">;</span>
        <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
    <span class="special">}</span>
<span class="special">};</span>

<span class="keyword">void</span> <span class="identifier">print_info</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">info</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">what</span><span class="special">)</span>
<span class="special">{</span>
    <span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">basic_info_walker</span><span class="special">;</span>

    <span class="identifier">printer</span> <span class="identifier">pr</span><span class="special">;</span>
    <span class="identifier">basic_info_walker</span><span class="special">&lt;</span><span class="identifier">printer</span><span class="special">&gt;</span> <span class="identifier">walker</span><span class="special">(</span><span class="identifier">pr</span><span class="special">,</span> <span class="identifier">what</span><span class="special">.</span><span class="identifier">tag</span><span class="special">,</span> <span class="number">0</span><span class="special">);</span>
    <span class="identifier">boost</span><span class="special">::</span><span class="identifier">apply_visitor</span><span class="special">(</span><span class="identifier">walker</span><span class="special">,</span> <span class="identifier">what</span><span class="special">.</span><span class="identifier">value</span><span class="special">);</span>
<span class="special">}</span>
</pre>
<p>
        </p>
<h6>
<a name="spirit.qi.reference.basics.h3"></a>
          <span class="phrase"><a name="spirit.qi.reference.basics.string"></a></span><a class="link" href="basics.html#spirit.qi.reference.basics.string">String</a>
        </h6>
<h6>
<a name="spirit.qi.reference.basics.h4"></a>
          <span class="phrase"><a name="spirit.qi.reference.basics.header"></a></span><a class="link" href="basics.html#spirit.qi.reference.basics.header">Header</a>
        </h6>
<pre class="programlisting"><span class="comment">// forwards to &lt;boost/spirit/home/support/string_traits.hpp&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">spirit</span><span class="special">/</span><span class="identifier">support_string_traits</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
</pre>
<p>
          A string can be any object <code class="computeroutput"><span class="identifier">s</span></code>,
          of type, <code class="computeroutput"><span class="identifier">S</span></code>, that satisfies
          the following expression traits:
        </p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
                  <p>
                    Expression
                  </p>
                </th>
<th>
                  <p>
                    Semantics
                  </p>
                </th>
</tr></thead>
<tbody>
<tr>
<td>
                  <p>
                    <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">traits</span><span class="special">::</span><span class="identifier">is_string</span><span class="special">&lt;</span><span class="identifier">S</span><span class="special">&gt;</span></code>
                  </p>
                </td>
<td>
                  <p>
                    Metafunction that evaluates to <code class="computeroutput"><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">true_</span></code>
                    if a certain type, <code class="computeroutput"><span class="identifier">S</span></code>
                    is a string, <code class="computeroutput"><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">false_</span></code>
                    otherwise (See <a href="../../../../../../../libs/mpl/doc/refmanual/integral-constant.html" target="_top">MPL
                    Boolean Constant</a>).
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">traits</span><span class="special">::</span><span class="identifier">char_type_of</span><span class="special">&lt;</span><span class="identifier">S</span><span class="special">&gt;</span></code>
                  </p>
                </td>
<td>
                  <p>
                    Metafunction that returns the underlying char type of a string
                    type, <code class="computeroutput"><span class="identifier">S</span></code>.
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">traits</span><span class="special">::</span><span class="identifier">get_c_string</span><span class="special">(</span><span class="identifier">s</span><span class="special">)</span></code>
                  </p>
                </td>
<td>
                  <p>
                    Function that returns the underlying raw C-string from <code class="computeroutput"><span class="identifier">s</span></code>.
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">traits</span><span class="special">::</span><span class="identifier">get_begin</span><span class="special">(</span><span class="identifier">s</span><span class="special">)</span></code>
                  </p>
                </td>
<td>
                  <p>
                    Function that returns an <a href="https://en.wikipedia.org/wiki/Standard_Template_Library" target="_top">STL</a>
                    iterator from <code class="computeroutput"><span class="identifier">s</span></code>
                    that points to the beginning the string.
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">traits</span><span class="special">::</span><span class="identifier">get_end</span><span class="special">(</span><span class="identifier">s</span><span class="special">)</span></code>
                  </p>
                </td>
<td>
                  <p>
                    Function that returns an <a href="https://en.wikipedia.org/wiki/Standard_Template_Library" target="_top">STL</a>
                    iterator from <code class="computeroutput"><span class="identifier">s</span></code>
                    that points to the end of the string.
                  </p>
                </td>
</tr>
</tbody>
</table></div>
<h6>
<a name="spirit.qi.reference.basics.h5"></a>
          <span class="phrase"><a name="spirit.qi.reference.basics.models"></a></span><a class="link" href="basics.html#spirit.qi.reference.basics.models">Models</a>
        </h6>
<p>
          Predefined models include:
        </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
              any literal string, e.g. "Hello, World",
            </li>
<li class="listitem">
              a pointer/reference to a null-terminated array of characters
            </li>
<li class="listitem">
              a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">basic_string</span><span class="special">&lt;</span><span class="identifier">Char</span><span class="special">&gt;</span></code>
            </li>
</ul></div>
<p>
          The namespace <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">traits</span></code> is open for users to provide their
          own specializations. The customization points implemented by <span class="emphasis"><em>Spirit.Qi</em></span>
          usable to customize the behavior of parsers are described in the section
          <a class="link" href="../../advanced/customize.html" title="Customization of Spirit's Attribute Handling">Customization of Attribute Handling</a>.
        </p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2001-2011 Joel de Guzman, Hartmut Kaiser<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="parser_concepts/nonterminal.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../reference.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="parse_api.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
